home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
SAT 2.3b4
/
Demo ƒ
/
myPlatform demo ƒ
/
sMovPlatform.p
< prev
next >
Wrap
Text File
|
1995-01-16
|
3KB
|
112 lines
{ Platform sprite, moveable version, not faceless }
unit sMovPlatForm;
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, Quickdraw,
{$ENDC}
SAT, sPlatForm;
var
platFace: FacePtr;
procedure InitMovPlatForm;
procedure SetupMovPlatForm (me: SpritePtr);
procedure HandleMovPlatForm (me: SpritePtr);
procedure HitMovPlatForm (me, him: SpritePtr);
implementation
procedure InitMovPlatForm;
var
i: integer;
begin
platFace := SATGetFace(138);
end;
procedure SetupMovPlatForm (me: SpritePtr);
var
r: Rect;
pol: PolyHandle;
begin
me^.speed.v := -1 + SATRand(2) * 2;
{me^.kind := -2; {Enemy kind}
me^.face := platFace;
SetRect(me^.hotRect, 0, 3, 60, 20);
me^.task := @HandleMovPlatform;
me^.hittask := @HitMovPlatform;
end;
procedure HandleMovPlatForm (me: SpritePtr);
begin
me^.position.v := me^.position.v + me^.speed.v;
if me^.position.v < 40 then
me^.speed.v := 1;
if me^.position.v > gSAT.offSizeV - 32 then
me^.speed.v := -1;
{Move}
if me^.speed.v = 0 then
if me^.position.v > gSAT.offSizeV div 2 then
me^.speed.v := -1
else
me^.speed.v := 1;
me^.layer := -me^.position.v;
end;
procedure HitMovPlatForm;
var
mini, i, min: integer;
diff: array[1..4] of integer;
begin
if him^.Task <> @HandlePlatForm then {check for HandleMovPlatForm too?}
begin
diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);{TtoB}
diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);{BtoT}
diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);{LtoR}
diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);{RtoL}
mini := 0;
min := 10000;
for i := 1 to 4 do
if min > diff[i] then
begin
min := diff[i];
mini := i;
end;
case mini of
1: {floor}
begin
him^.position.v := him^.position.v - diff[1] + 2;
him^.kind := 10; {Signal to him, as if we used KindCollision}
if him^.speed.v > 0 then
him^.speed.v := 0;
end;
2: {cieling (sp?)}
begin
him^.position.v := him^.position.v + diff[2] + 1;
{No signal here}
if him^.speed.v < 0 then
him^.speed.v := -him^.speed.v;
end;
3: {left}
begin
him^.position.h := him^.position.h - diff[3] - 1;
him^.kind := 10; {Signal to him, as if we used KindCollision}
if him^.speed.h > 0 then
him^.speed.h := -him^.speed.h;
end;
4: {right}
begin
him^.position.h := him^.position.h + diff[4] + 1;
him^.kind := 10; {Signal to him, as if we used KindCollision}
if him^.speed.h < 0 then
him^.speed.h := -him^.speed.h;
end;
end;{case}
end; {if}
end; {HitMovPlatForm}
end.{of unit}